namespace SimpleWebServices.Configuration
{
    using System.Configuration;
    using System.Xml;
    using Xunit;

    public sealed class MaintenanceConfigurationFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<MaintenanceConfiguration>()
                .DerivesFrom<object>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .Implements<IConfigurationSectionHandler>()
                .Result);
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new MaintenanceConfiguration());
        }

        [Fact]
        public void op_Settings()
        {
            Assert.NotNull(MaintenanceConfiguration.Settings());
        }

        [Fact]
        public void op_Settings_string()
        {
            Assert.NotNull(MaintenanceConfiguration.Settings("simplewebservices/maintenance"));
        }

        [Fact]
        public void op_Create_object_object_XmlNodeNull()
        {
            MaintenanceSettings actual = new MaintenanceConfiguration().Create(null, null, null as XmlNode) as MaintenanceSettings;

            Assert.False(actual.Enabled);
        }

        [Fact]
        public void op_Create_object_object_XmlNodeEmpty()
        {
            XmlDocument xml = new XmlDocument();
            xml.LoadXml("<maintenance />");

            MaintenanceSettings actual = new MaintenanceConfiguration().Create(null, null, xml.DocumentElement) as MaintenanceSettings;

            Assert.False(actual.Enabled);
        }

        [Fact]
        public void op_Create_object_object_XmlNode()
        {
            XmlDocument xml = new XmlDocument();
            xml.LoadXml("<maintenance enabled='true' />");

            MaintenanceSettings actual = new MaintenanceConfiguration().Create(null, null, xml.DocumentElement) as MaintenanceSettings;

            Assert.True(actual.Enabled);
        }

        [Fact]
        public void op_Create_object_object_XmlNodeInvalid()
        {
            XmlDocument xml = new XmlDocument();
            xml.LoadXml("<bad-name/>");

            Assert.Throws<ConfigurationErrorsException>(() => new MaintenanceConfiguration().Create(null, null, xml.DocumentElement));
        }
    }
}